﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RealtyManagementSystem.DAL;

namespace RealtyManagementSystem.Web.Common
{
    public partial class ViewAnnouncements : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //TODO
            if (!IsPostBack)
            {
                BindAnnounce();
            }
        }

        private void BindAnnounce()
        {
            using (var contxt = new realtydbEntities())
            {
                var anns = (from a in contxt.Announcements.Include("aspnet_Users")
                            orderby a.AnnounceId descending
                            select new
                            {
                                Id = a.AnnounceId,
                                Title = a.Title,
                                CreateDate = a.CreateDate,
                                Name = a.aspnet_Users.UserName
                            }).ToList();
                gvAnns.AutoGenerateColumns = false;
                gvAnns.DataSource = anns;
                gvAnns.DataBind();
            }
        }
    }//clas
}